package com.lry.util;

import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

/**
 * spring有提供pathmatcher
 */
public class PathUtil {
    /**
     * 路径匹配
     *
     * @param patternPath 匹配表达式
     * @param actualPath 匹配路径
     * @return true:匹配成功
     */
    public static boolean match(String actualPath,String patternPath ) {
        if (StringHelper.isEmpty(patternPath) || StringHelper.isEmpty(actualPath)) {
            return false;
        }
        PathMatcher matcher = new AntPathMatcher();
        return matcher.match(patternPath, actualPath);
    }

    /**
     * 忽略的路径检测
     * @param actulPath 实际路径
     * @param path 路径表达式
     * @return
     */
    public static boolean match(String actulPath,String... path) {
        if (path.length < 1) {
            return false;
        }
        for (String p : path) {
            if (match(actulPath,p)) {
                return true;
            }
        }
        return false;
    }
}
